import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;




public class MySemanticAnalyzer {
	
	
	//This class takes the array list that is the parse tree and changes it into HTML code! It goes through the if
	//statements while the arraylist is not empty and checks each one to see which statement the current index holds. 
	//when it finds it, it adds it to the html output document and then does the same thing until the arraylist is empty.
	//this completes the process!
	public void html() throws FileNotFoundException {
		
		PrintStream out = new PrintStream(new FileOutputStream("Test1.html"));
		
		while (!Compiler.parsetree.isEmpty()){
			String currenttag = Compiler.parsetree.get(0);
			if (currenttag.equalsIgnoreCase("#DEFINE")){
				//not sure how to do this one....
			}
			if (currenttag.equalsIgnoreCase("#START DOCUMENT")){
				out.println("<html>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END DOCUMENT")){
				out.println("</html>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START HEAD")){
				out.println("<head>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END HEAD")){
				out.println("</head>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START TITLE")){
				out.println("<title> ");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END TITLE")){
				out.print(" </title>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START PARAGRAPH")){
				out.println("<p>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END PARAGRAPH")){
				out.print("</p>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START BOLD")){
				out.println("<b>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END BOLD")){
				out.print("</b>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START ITALICS")){
				out.println("<i>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END ITALICS")){
				out.print("</i>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START LIST")){
				out.println("<ul>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END LIST")){
				out.print("</ul>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START LIST")){
				out.println("<li>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END LIST")){
				out.print("</li>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#NEWLINE")){
				out.print("<br>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START AUDIO")){
				out.println("<audio controls>");
				out.print("<source src=");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END AUDIO")){
				out.print(">");
				out.print("</audio>");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#START VIDEO")){
				out.println("<iframe src='");
				Compiler.parsetree.remove(0);
			}
			else if (currenttag.equalsIgnoreCase("#END VIDEO")){
				out.print("/>'");
				Compiler.parsetree.remove(0);
			}
			else { //this should be fore text
				out.print(currenttag);
				Compiler.parsetree.remove(0);
			}
		}
	}
}
